package com.bianguo.android.iocdemo.view.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;

import com.bianguo.android.injectlibrary.annotations.ContentView;
import com.bianguo.android.injectlibrary.annotations.InjectView;
import com.bianguo.android.iocdemo.R;
import com.bianguo.android.iocdemo.utils.BitmapUtil;
import com.bianguo.android.iocdemo.view.widget.DiscView;
import com.bianguo.android.iocdemo.view.widget.PlayerBgLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.DrawableImageViewTarget;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;

import java.util.ArrayList;

import jp.wasabeef.glide.transformations.BlurTransformation;

@ContentView(R.layout.activity_player)
public class PlayerActivity extends BaseActivity implements DiscView.OnPageChangeListener {

    @InjectView(R.id.player_root_layout)
    PlayerBgLayout rootLayout;
    @InjectView(R.id.discview)
    DiscView discView;

    private ArrayList<Integer> mMusicBgIds;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mMusicBgIds = new ArrayList<>();
        mMusicBgIds.add(R.drawable.ic_music1);
        mMusicBgIds.add(R.drawable.ic_music2);
        mMusicBgIds.add(R.drawable.ic_music3);
        discView.setOnPageChangeListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        discView.setMusicDataList(mMusicBgIds);
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onPageChanged(int position) {
        RequestBuilder<Drawable> requestBuilder = Glide.with(this)
                .load(mMusicBgIds.get(position))
                .apply(RequestOptions.bitmapTransform(new BlurTransformation(200, 3)));
        requestBuilder.into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                rootLayout.setForeground(resource);
            }
        });
    }
}
